package org.example.service;

import com.alibaba.fastjson.JSON;
import com.aliyun.dingtalkim_1_0.models.*;
import com.aliyun.dingtalkrobot_1_0.Client;
import com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendHeaders;
import com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendRequest;
import com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendResponse;
import com.aliyun.tea.TeaException;
import com.dingtalk.open.app.api.models.bot.ChatbotMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import com.aliyun.tea.TeaException;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

/**
 * @author zeymo
 */
@Slf4j
@Service
public class RobotGroupMessagesService {
    private Client robotClient;
    private final AccessTokenService accessTokenService;

    @Value("${robot.code}")
    private String robotCode;

    @Autowired
    public RobotGroupMessagesService(AccessTokenService accessTokenService) {
        this.accessTokenService = accessTokenService;
    }

    @PostConstruct
    public void init() throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
        config.protocol = "https";
        config.regionId = "central";
        robotClient = new Client(config);
    }

    /**
     * send message to group with openConversationId
     *
     * @param openConversationId conversationId
     * @return messageId
     * @throws Exception e
     */
    public String send(String openConversationId, String text) throws Exception {
        OrgGroupSendHeaders orgGroupSendHeaders = new OrgGroupSendHeaders();
        orgGroupSendHeaders.setXAcsDingtalkAccessToken(accessTokenService.getAccessToken());

        OrgGroupSendRequest orgGroupSendRequest = new OrgGroupSendRequest();
        orgGroupSendRequest.setMsgKey("sampleText");
        orgGroupSendRequest.setMsgKey("sampleMarkdown");
        orgGroupSendRequest.setMsgKey("sampleImageMsg");
        orgGroupSendRequest.setMsgKey("sampleLink");
        orgGroupSendRequest.setMsgKey("sampleActionCard");
        orgGroupSendRequest.setMsgKey("sampleActionCard2");
//        orgGroupSendRequest.setMsgKey("sampleActionCard6");
        orgGroupSendRequest.setRobotCode(robotCode);

        orgGroupSendRequest.setOpenConversationId(openConversationId);

//        JSONObject msgParam = new JSONObject();
//        msgParam.put("content", "java-getting-start say : " + text);
        orgGroupSendRequest.setMsgParam("这是一个文本内容");
        orgGroupSendRequest.setMsgParam("{\n" +
                "    \"title\": \"Markdown标题\"，\n" +
                "    \"text\": \"Markdown内容\"\n" +
                "  }");
        //图片
        orgGroupSendRequest.setMsgParam("{\n" +
                "    \"photoURL\": \"https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/1922002861/p634077.png\"\n" +
                "  }");
        //sampleLink消息测试
        orgGroupSendRequest.setMsgParam("{\n" +
                "    \n" +
                "     \"text\": \"消息内容测试\",\n" +
                "     \"title\": \"sampleLink消息测试\",\n" +
                "     \"picUrl\": \"@lADOADmaWMzazQKA\",\n" +
                "     \"messageUrl\": \"http://dingtalk.com\"\n" +
                "    \n" +
                "}");
        orgGroupSendRequest.setMsgParam("{\n" +
                "     \"title\": \"测试标题\",\n" +
                "     \"text\": \"内容测试\",\n" +
                "     \"singleTitle\": \"查看详情\",\n" +
                "     \"singleURL\": \"https://open.dingtalk.com\"\n" +
                "}");
        orgGroupSendRequest.setMsgParam("{\n" +
                "     \"title\": \"消息标题测试\",\n" +
                "     \"text\": \"消息正文测试\",\n" +
                "     \"actionTitle1\": \"一个按钮\",\n" +
                "     \"actionURL1\": \"https://www.taobao.com\",\n" +
                "     \"actionTitle2\": \"两个按钮\",\n" +
                "     \"actionURL2\": \"https://www.tmall.com\"\n" +
                "}");
        //卡片消息：横向二个按钮。
/*        orgGroupSendRequest.setMsgParam("{\n" +
                "    \"title\": \"标题\",\n" +
                "    \"text\": \"xxx员工提交的工单申请\n是否同意\",\n" +
                "    \"buttonTitle1\":\"同意\",\n" +
                "    \"buttonUrl1\":\"https://www.tmall.com\",\n" +
                "    \"buttonTitle2\":\"拒绝\",\n" +
                "    \"buttonUrl2\":\"https://www.taobao.com\"\n" +
                "  }");*/

        try {
            OrgGroupSendResponse orgGroupSendResponse = robotClient.orgGroupSendWithOptions(orgGroupSendRequest,
                    orgGroupSendHeaders, new com.aliyun.teautil.models.RuntimeOptions());
            if (Objects.isNull(orgGroupSendResponse) || Objects.isNull(orgGroupSendResponse.getBody())) {
                log.error("RobotGroupMessagesService_send orgGroupSendWithOptions return error, response={}",
                        orgGroupSendResponse);
                return null;
            }
            return orgGroupSendResponse.getBody().getProcessQueryKey();
        } catch (TeaException e) {
            log.error("RobotGroupMessagesService_send orgGroupSendWithOptions throw TeaException, errCode={}, " +
                    "errorMessage={}", e.getCode(), e.getMessage(), e);
            throw e;
        } catch (Exception e) {
            log.error("RobotGroupMessagesService_send orgGroupSendWithOptions throw Exception", e);
            throw e;
        }
    }


    /**
     * 发送互动卡片
     */
    public void sendDingCard(ChatbotMessage message) throws Exception {
//        Config config = new Config();
//        config.protocol = "https";
//        config.regionId = "central";

        Map<String, Object> content = new HashMap<>();
        content.put("nickName", message.getSenderNick());
        content.put("userId", message.getSenderStaffId());
        ArrayList<Object> objectArrayList = new ArrayList<>();
        objectArrayList.add(content);
        com.aliyun.dingtalkim_1_0.Client client = Sample.createClient();
        SendRobotInteractiveCardHeaders sendRobotInteractiveCardHeaders = new SendRobotInteractiveCardHeaders();
        sendRobotInteractiveCardHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
        SendRobotInteractiveCardRequest.SendRobotInteractiveCardRequestSendOptions sendOptions = new SendRobotInteractiveCardRequest.SendRobotInteractiveCardRequestSendOptions()
                .setAtUserListJson("[{\"nickName\":\"小齐\",\"userId\":\"08521816421284272\"}]")
                .setAtAll(false)
                .setReceiverListJson("[{\"userId\":\"08521816421284272\"}]");
        SendRobotInteractiveCardRequest sendRobotInteractiveCardRequest = new SendRobotInteractiveCardRequest()
                //固定填写：
                .setCardTemplateId("StandardCard")
                //群会话id
//                .setOpenConversationId(message.getConversationId())
                .setSingleChatReceiver(JSON.toJSONString(content))
                //发送不同卡片内容，需传入不同的cardBizId。
                .setCardBizId("dingCard1001")
                //机器人ID，当该机器人为企业内部开发-机器人时，填写机器人应用的appKey
                //其他机器人填写机器人的robotCode值
                .setRobotCode(robotCode)
                .setCardData("{\n" +
                        "  \"config\": {\n" +
                        "    \"autoLayout\": true,\n" +
                        "    \"enableForward\": true\n" +
                        "  },\n" +
                        "  \"header\": {\n" +
                        "    \"title\": {\n" +
                        "      \"type\": \"text\",\n" +
                        "      \"text\": \"订餐\",\n" +
                        "      \"color\": \"common_green1_color\"\n" +
                        "    },\n" +
                        "    \"logo\": \"@lALPDrz7jNRJdJE4OA\"\n" +
                        "  },\n" +
                        "  \"contents\": [\n" +
                        "    {\n" +
                        "      \"type\": \"image\",\n" +
                        "      \"image\": \"@lALPDfYH0aWc_a3NAljNAyA\",\n" +
                        "      \"ratio\": \"16:9\",\n" +
                        "      \"id\": \"image_1653901065785\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"markdown\",\n" +
                        "      \"text\": \"套餐内容：*西兰花、胡萝卜、鸡蛋、荞麦面、玉米、莴笋、紫薯*\",\n" +
                        "      \"id\": \"markdown_1653901065785\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"section\",\n" +
                        "      \"content\": {\n" +
                        "        \"type\": \"text\",\n" +
                        "        \"text\": \"主菜选择：\",\n" +
                        "        \"id\": \"text_1653901065785\"\n" +
                        "      },\n" +
                        "      \"extra\": {\n" +
                        "        \"type\": \"select\",\n" +
                        "        \"options\": [\n" +
                        "          {\n" +
                        "            \"label\": {\n" +
                        "              \"type\": \"text\",\n" +
                        "              \"text\": \"? 鸡肉\",\n" +
                        "              \"id\": \"text_1653901065786\"\n" +
                        "            },\n" +
                        "            \"value\": \"1\"\n" +
                        "          },\n" +
                        "          {\n" +
                        "            \"label\": {\n" +
                        "              \"type\": \"text\",\n" +
                        "              \"text\": \"? 牛肉\",\n" +
                        "              \"id\": \"text_1653901065870\"\n" +
                        "            },\n" +
                        "            \"value\": \"2\"\n" +
                        "          }\n" +
                        "        ],\n" +
                        "        \"placeholder\": {\n" +
                        "          \"type\": \"text\",\n" +
                        "          \"text\": \"请选择\",\n" +
                        "          \"id\": \"text_1653901065835\"\n" +
                        "        },\n" +
                        "        \"id\": \"select_1647330112516\"\n" +
                        "      },\n" +
                        "      \"id\": \"section_1653901065785\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"section\",\n" +
                        "      \"content\": {\n" +
                        "        \"type\": \"text\",\n" +
                        "        \"text\": \"取餐地点：\",\n" +
                        "        \"id\": \"text_1653901065850\"\n" +
                        "      },\n" +
                        "      \"extra\": {\n" +
                        "        \"type\": \"select\",\n" +
                        "        \"options\": [\n" +
                        "          {\n" +
                        "            \"label\": {\n" +
                        "              \"type\": \"text\",\n" +
                        "              \"text\": \"5号楼取餐点\",\n" +
                        "              \"id\": \"text_1653901065847\"\n" +
                        "            },\n" +
                        "            \"value\": \"1\"\n" +
                        "          },\n" +
                        "          {\n" +
                        "            \"label\": {\n" +
                        "              \"type\": \"text\",\n" +
                        "              \"text\": \"10号楼取餐点\",\n" +
                        "              \"id\": \"text_1653901065912\"\n" +
                        "            },\n" +
                        "            \"value\": \"2\"\n" +
                        "          },\n" +
                        "          {\n" +
                        "            \"label\": {\n" +
                        "              \"type\": \"text\",\n" +
                        "              \"text\": \"餐厅服务台\",\n" +
                        "              \"id\": \"text_1653901065845\"\n" +
                        "            },\n" +
                        "            \"value\": \"3\"\n" +
                        "          }\n" +
                        "        ],\n" +
                        "        \"placeholder\": {\n" +
                        "          \"type\": \"text\",\n" +
                        "          \"text\": \"请选择\",\n" +
                        "          \"id\": \"text_1653901065892\"\n" +
                        "        },\n" +
                        "        \"id\": \"select_1647330167899\"\n" +
                        "      },\n" +
                        "      \"id\": \"section_1653901065862\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"action\",\n" +
                        "      \"actions\": [\n" +
                        "        {\n" +
                        "          \"type\": \"button\",\n" +
                        "          \"label\": {\n" +
                        "            \"type\": \"text\",\n" +
                        "            \"text\": \"一键预定\",\n" +
                        "            \"id\": \"text_1653901065910\"\n" +
                        "          },\n" +
                        "          \"actionType\": \"request\",\n" +
                        "          \"status\": \"primary\",\n" +
                        "          \"id\": \"button_1647330333211\"\n" +
                        "        }\n" +
                        "      ],\n" +
                        "      \"id\": \"action_1653901065786\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"divider\",\n" +
                        "      \"id\": \"divider_1653901065786\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"markdown\",\n" +
                        "      \"text\": \"**3月15日健康餐已预定：24/40 份**\",\n" +
                        "      \"id\": \"markdown_1653901065786\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"markdown\",\n" +
                        "      \"text\": \"<font color=common_level3_base_color>赫莎莎 牛肉套餐</font>\",\n" +
                        "      \"icon\": \"@lALPDsCJC3kB4IYwMA\",\n" +
                        "      \"id\": \"markdown_1653901065823\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"markdown\",\n" +
                        "      \"text\": \"<font color=common_level3_base_color>周小丽 牛肉套餐</font>\",\n" +
                        "      \"icon\": \"@lALPDsekCMKd0tMwMA\",\n" +
                        "      \"id\": \"markdown_1653901065846\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"markdown\",\n" +
                        "      \"text\": \"<font color=common_level3_base_color>黄敏敏 牛肉套餐</font>\",\n" +
                        "      \"icon\": \"@lALPEBkmB-g2_NIwMA\",\n" +
                        "      \"id\": \"markdown_1653901065886\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"action\",\n" +
                        "      \"actions\": [\n" +
                        "        {\n" +
                        "          \"type\": \"button\",\n" +
                        "          \"label\": {\n" +
                        "            \"type\": \"text\",\n" +
                        "            \"text\": \"查看全部\",\n" +
                        "            \"id\": \"text_1653901065843\"\n" +
                        "          },\n" +
                        "          \"actionType\": \"openLink\",\n" +
                        "          \"url\": {\n" +
                        "            \"all\": \"https://www.dingtalk.com\"\n" +
                        "          },\n" +
                        "          \"status\": \"normal\",\n" +
                        "          \"id\": \"button_1647330728999\"\n" +
                        "        }\n" +
                        "      ],\n" +
                        "      \"id\": \"action_1653901065859\"\n" +
                        "    }\n" +
                        "  ]\n" +
                        "}")
                .setSendOptions(sendOptions);
        try {
            SendRobotInteractiveCardResponse sendRobotInteractiveCardResponse = client.sendRobotInteractiveCardWithOptions(sendRobotInteractiveCardRequest, sendRobotInteractiveCardHeaders, new RuntimeOptions());
            System.out.println(JSON.toJSONString(sendRobotInteractiveCardResponse.getBody()));
        } catch (TeaException err) {
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
                System.out.println(err.code);
                System.out.println(err.message);
            }

        } catch (Exception _err) {
            TeaException err = new TeaException(_err.getMessage(), _err);
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
                System.out.println(err.code);
                System.out.println(err.message);
            }
        }
    }

    /**
     * 更新互动卡片
     */
    public void interactiveCardsUpdate(ChatbotMessage message) throws Exception {
//        Config config = new Config();
//        config.protocol = "https";
//        config.regionId = "central";
        com.aliyun.dingtalkim_1_0.Client client = Sample.createClient();
        UpdateRobotInteractiveCardHeaders updateRobotInteractiveCardHeaders = new UpdateRobotInteractiveCardHeaders();
        updateRobotInteractiveCardHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();;
        UpdateRobotInteractiveCardRequest.UpdateRobotInteractiveCardRequestUpdateOptions updateOptions = new UpdateRobotInteractiveCardRequest.UpdateRobotInteractiveCardRequestUpdateOptions()
                .setUpdateCardDataByKey(true);
        UpdateRobotInteractiveCardRequest updateRobotInteractiveCardRequest = new UpdateRobotInteractiveCardRequest()
                .setCardBizId("dingCard1001")
                .setCardData("{\"contents\": [\n" +
                        "    {\n" +
                        "      \"type\": \"image\",\n" +
                        "      \"image\": \"@lALPDfYH0aWc_a3NAljNAyA\",\n" +
                        "      \"ratio\": \"16:9\",\n" +
                        "      \"id\": \"image_1653901065785\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"markdown\",\n" +
                        "      \"text\": \"套餐内容：*西兰花、胡萝卜、鸡蛋、荞麦面、玉米、莴笋、紫薯*\",\n" +
                        "      \"id\": \"markdown_1653901065785\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"section\",\n" +
                        "      \"content\": {\n" +
                        "        \"type\": \"text\",\n" +
                        "        \"text\": \"主菜选择：\",\n" +
                        "        \"id\": \"text_1653901065785\"\n" +
                        "      },\n" +
                        "      \"extra\": {\n" +
                        "        \"type\": \"select\",\n" +
                        "        \"options\": [\n" +
                        "          {\n" +
                        "            \"label\": {\n" +
                        "              \"type\": \"text\",\n" +
                        "              \"text\": \"? 鸡肉\",\n" +
                        "              \"id\": \"text_1653901065786\"\n" +
                        "            },\n" +
                        "            \"value\": \"1\"\n" +
                        "          },\n" +
                        "          {\n" +
                        "            \"label\": {\n" +
                        "              \"type\": \"text\",\n" +
                        "              \"text\": \"? 牛肉\",\n" +
                        "              \"id\": \"text_1653901065870\"\n" +
                        "            },\n" +
                        "            \"value\": \"2\"\n" +
                        "          }\n" +
                        "        ],\n" +
                        "        \"placeholder\": {\n" +
                        "          \"type\": \"text\",\n" +
                        "          \"text\": \"请选择\",\n" +
                        "          \"id\": \"text_1653901065835\"\n" +
                        "        },\n" +
                        "        \"id\": \"select_1647330112516\"\n" +
                        "      },\n" +
                        "      \"id\": \"section_1653901065785\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"section\",\n" +
                        "      \"content\": {\n" +
                        "        \"type\": \"text\",\n" +
                        "        \"text\": \"取餐地点：\",\n" +
                        "        \"id\": \"text_1653901065850\"\n" +
                        "      },\n" +
                        "      \"extra\": {\n" +
                        "        \"type\": \"select\",\n" +
                        "        \"options\": [\n" +
                        "          {\n" +
                        "            \"label\": {\n" +
                        "              \"type\": \"text\",\n" +
                        "              \"text\": \"5号楼取餐点\",\n" +
                        "              \"id\": \"text_1653901065847\"\n" +
                        "            },\n" +
                        "            \"value\": \"1\"\n" +
                        "          },\n" +
                        "          {\n" +
                        "            \"label\": {\n" +
                        "              \"type\": \"text\",\n" +
                        "              \"text\": \"10号楼取餐点\",\n" +
                        "              \"id\": \"text_1653901065912\"\n" +
                        "            },\n" +
                        "            \"value\": \"2\"\n" +
                        "          },\n" +
                        "          {\n" +
                        "            \"label\": {\n" +
                        "              \"type\": \"text\",\n" +
                        "              \"text\": \"餐厅服务台\",\n" +
                        "              \"id\": \"text_1653901065845\"\n" +
                        "            },\n" +
                        "            \"value\": \"3\"\n" +
                        "          }\n" +
                        "        ],\n" +
                        "        \"placeholder\": {\n" +
                        "          \"type\": \"text\",\n" +
                        "          \"text\": \"请选择\",\n" +
                        "          \"id\": \"text_1653901065892\"\n" +
                        "        },\n" +
                        "        \"id\": \"select_1647330167899\"\n" +
                        "      },\n" +
                        "      \"id\": \"section_1653901065862\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"action\",\n" +
                        "      \"actions\": [\n" +
                        "        {\n" +
                        "          \"type\": \"button\",\n" +
                        "          \"label\": {\n" +
                        "            \"type\": \"text\",\n" +
                        "            \"text\": \"一键预定\",\n" +
                        "            \"id\": \"text_1653901065910\"\n" +
                        "          },\n" +
                        "          \"actionType\": \"request\",\n" +
                        "          \"status\": \"primary\",\n" +
                        "          \"id\": \"button_1647330333211\",\n" +
                        "          \"value\": \"1\"\n" +
                        "        }\n" +
                        "      ],\n" +
                        "      \"id\": \"action_1653901065786\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"divider\",\n" +
                        "      \"id\": \"divider_1653901065786\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"markdown\",\n" +
                        "      \"text\": \"**6月1日健康餐已预定：23/40 份**\",\n" +
                        "      \"id\": \"markdown_1653901065786\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"markdown\",\n" +
                        "      \"text\": \"<font color=common_level3_base_color>小钉 牛肉套餐</font>\",\n" +
                        "      \"icon\": \"@lALPDsCJC3kB4IYwMA\",\n" +
                        "      \"id\": \"markdown_1653901065823\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"markdown\",\n" +
                        "      \"text\": \"<font color=common_level3_base_color>阿黄同学 牛肉套餐</font>\",\n" +
                        "      \"icon\": \"@lALPDsekCMKd0tMwMA\",\n" +
                        "      \"id\": \"markdown_1653901065846\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"markdown\",\n" +
                        "      \"text\": \"<font color=common_level3_base_color>阿黄同学2 牛肉套餐</font>\",\n" +
                        "      \"icon\": \"@lALPEBkmB-g2_NIwMA\",\n" +
                        "      \"id\": \"markdown_1653901065886\"\n" +
                        "    },\n" +
                        "    {\n" +
                        "      \"type\": \"action\",\n" +
                        "      \"actions\": [\n" +
                        "        {\n" +
                        "          \"type\": \"button\",\n" +
                        "          \"label\": {\n" +
                        "            \"type\": \"text\",\n" +
                        "            \"text\": \"查看全部\",\n" +
                        "            \"id\": \"text_1653901065843\"\n" +
                        "          },\n" +
                        "          \"actionType\": \"openLink\",\n" +
                        "          \"url\": {\n" +
                        "            \"all\": \"https://www.dingtalk.com\"\n" +
                        "          },\n" +
                        "          \"status\": \"normal\",\n" +
                        "          \"id\": \"button_1647330728999\"\n" +
                        "        }\n" +
                        "      ],\n" +
                        "      \"id\": \"action_1653901065859\"\n" +
                        "    }\n" +
                        "  ]}")
                .setUpdateOptions(updateOptions);
        try {
            UpdateRobotInteractiveCardResponse updateRobotInteractiveCardResponse = client.updateRobotInteractiveCardWithOptions(updateRobotInteractiveCardRequest, updateRobotInteractiveCardHeaders, new RuntimeOptions());
            System.out.println(JSON.toJSONString(updateRobotInteractiveCardResponse.getBody()));
        } catch (TeaException err) {
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
                System.out.println(err.code);
                System.out.println(err.message);
            }

        } catch (Exception _err) {
            TeaException err = new TeaException(_err.getMessage(), _err);
            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
                System.out.println(err.code);
                System.out.println(err.message);
            }
        }
    }
}
